<div class="list-body">
	<form id="user-search-form" data-toggle="ajaxform" data-options="{beforeSubmit:setUserSearchValue,url: '/user/list',validate: false,okalert:false,loadingmask: true,okCallback:getUserListData}">
    <div class="row">
  		<div class="search-input">
          	<input type="text"  id="user-name-input" placeholder="输入用户名称" autocomplete="off"  onblur="Trim(this,this.value)">
            <input type="text" name="name" id="userNameDisNone" style="display: none;"> <!--删？ -->
  			<div style="display: none;">
                      <input type="text" name="pageCurrent" value="1">
                      <input type="text" name="pageSize" value="12">
                  </div>
              <!-- <a class="search-btn"><i class="fa fa-search"></i></a> -->
             <button type="submit"  class="search-btn" data-icon="search"></button>
      	</div>
      	<a class="add-btn"  onclick="dialog_user_add()"><i class="fa fa-plus-square-o"></i><span>添加用户</span></a>
  	</div>
	
  </form>
    <ul class="row user-list-content list-content">

    </ul>
    <div id="pagination_user" style="text-align: center;display: none;"></div>
</div>


<script type="text/javascript">
$(function(){
     var userTotalNum ;
     pagination_callback(1, 12,1);
     $("input").placeholder();
 })

function setUserSearchValue(from){
  $('#user-name-input').val()!='输入用户名称' ? $('#userNameDisNone').val($('#user-name-input').val()) : $('#userNameDisNone').val('');
  return true;
}
function getUserListData(json, options){
    $('#pagination_user').pagination('destroy')     //每次提交前删掉之前的分页数据
    $('#pagination_user').pagination({               //搜索后分页
      total:json.totalRow, pageSize:12, callback:pagination_callback
    })
    userTotalNum =json.totalRow;
    set_list(json);
    if(json.totalRow<=12){
      $("#pagination_user").css("display","none");
    }else{
      $("#pagination_user").css("display","block");
    }
}
function pagination_callback(pageCurrent, pageSize,num) {    //初始化分页参数
     var userName=$("#userNameDisNone").val(); // //取出存进的参数值
     
      BJUI.ajax('doajax', {
          url: '/user/list',
          okalert:false,
          type:'post',
          data: {pageCurrent:pageCurrent, pageSize:pageSize,name:userName},  //此处传递输入的信息给后台
          okCallback: function(json, options) { 
          set_list(json);
              if(num==1){
                 $('#pagination_user').pagination({
                total:json.totalRow, pageSize:12, callback:pagination_callback
                 }) 
              }
              userTotalNum =json.totalRow;
              if(json.totalRow>pageSize){
                  $("#pagination_user").css("display","block");
              }else{
                $("#pagination_user").css("display","none");
            }
          }
       })
}


function set_list(json){
    $('.user-list-content').empty();
    var btnArr=[
        {title:"编辑",icon:"fa fa-edit",fun:"user_edit"},
        {title:"详情",icon:"fa fa-list-alt",fun:"user_details"},
        {title:"删除",icon:"fa fa-trash-o",fun:"user_del"},
      ];
    $('.user-list-content').setList(json.list,btnArr,'fa-user');
  
    }

function dialog_user_add(){
      BJUI.dialog({
      id:"userAdd",
      url:"/user/editPage",
      title:"添加用户",
      type:"post",
      width:"620",
      height:"600",
      mask:true,
      maxable:false
  })
}
function user_details(obj){
    var id=$(obj).parent().parent().prevAll("#item-id").text();
    BJUI.dialog({
         id:"userdetails",
         url:"/user/detailsPage",
         title:"详情",
         type:"post",
         data:{"id":id},
         width:"620",
         height:"600",
         mask:true,
         maxable:false
    }) 
      
}
function user_edit(obj){
    var id=$(obj).parent().parent().prevAll("#item-id").text();
    BJUI.dialog({
         id:"userEdit",
         url:"/user/editPage",
         title:"编辑用户",
         type:"post",
         data:{"id":id},
         width:"620",
         height:"600",
         mask:true,
         maxable:false
    }) 
}
   
   
function user_del(obj){
     var id=$(obj).parent().parent().prevAll("#item-id").text();
      BJUI.alertmsg('confirm', '确定要删除吗！', {
        okCall: function() {
          BJUI.ajax('doajax',{
            url:"/user/del",
            type:"post",
            dataType:"json",
            data:{"id":id},
            loadingmask: true,
            okCallback: function(json, options) {
              
               userTotalNum -=1;
                $('#pagination_user').pagination('destroy')
                $('#pagination_user').pagination({
            total:userTotalNum, pageSize:12, callback:pagination_callback
        });
                  pagination_callback(1,12,1);
            }
        })
        }
    })
 }
</script>

